<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
        <div class="center_box">
        	<div class="center_box_nav">
            	<div class="center_banner">
                	<a href="javascript:location.href='${ctx}/front!viewIndex.action';" title="首页">首页</a>&gt;&nbsp;${name1}&gt;&nbsp;${name2}&gt;&nbsp;${name3}
                </div>     
                <form id='keyForm'>          
                <ul class="orditions float_lf">
                    <li>
                        <a href="javascript:order=1;doQuery();" title="人气" class="ordition_bt ordition_acc">人气<b></b></a>
                    </li>
                    <li>
                        <a href="javascript:order=2;doQuery();" title="评论" class="ordition_bt ordition_hot">评论<b></b></a>
                    </li>
                    <li>
                        <input type="text" id="q_key" name="q_key"/>
                        <a href="javascript:order=0;doQuery();" title="确定" class="ordition_sure">确定</a>
                    </li>
                </ul>     
                </form>           
                <div class="list_page float_rg">
						<span>第</span>
						<span class="page_go">
							<input type="text" id="page_top" value="1"/><a href="javascript:clickGo('page_top');" class="page_go_bt"></a>
						</span>
						<span id="allPage_show_top">页 共1页</span>                        
						<a href="javascript:movePre();"  id='preBt_top' class="page_pre_unable"></a>
						<a href="javascript:moveNext();" id='nextBt_top' class="page_next"></a> 
                </div>
             </div>
            <div class="list_show clearfix">
            	<ul class="list_inner clearfix"  id='goodsContent'></ul>              
              	<div class="list_page">
					<div class="list_page_inner">
						<span>第</span>
						<span class="page_go">
							<input type="text" id="page" value="1"/><a href="javascript:clickGo('page');" class="page_go_bt"></a>
						</span>
						<span id="allPage_show">页 共1页</span>                        
						<a href="javascript:movePre();"  id='preBt' class="page_pre_unable"></a>
						<a href="javascript:moveNext();" id='nextBt' class="page_next"></a>
					</div>                    
				</div>
            </div>	
        </div>
<script type="text/javascript">
<!--
var pageSize=20;//商品列表页面大小
var allPage;//总页数
var allCount;//总记录数
var curPage=1;//当前页数
var order=0;//排序方式

//查询商品列表
function doQuery(){	
	var url="${ctx}/front!getList.action?q_classId=${classId}&page="+curPage+"&pageSize="+pageSize+"&q_order="+order;
	$.post(url, $("#keyForm").serialize() ,function callback(txt){   
		var json = $.parseJSON(txt);
			if (json.code==0) {	
				allCount=json.count;
				createNotes(json.info);	
				refreshPageUI();
			}else{
				alert('查询商品列表失败！');
			}
		}	
	);
}
//创建商品列表数据
function createNotes(objs){		
	var c="";
	for(var i=0;i<objs.length;i++){
		var obj=objs[i];		
		c+='<li>';
		c+='<div class="bb_pd_cell">';
		c+='    <p class="bb_pd_pic">';
		c+='        <a href="#">';
		c+='            <img src="${ctx}/frontSys!getPic.action?name='+obj.goodsPic+'" alt="'+obj.goodsName+'" />';
		c+='        </a>';
		c+='    </p>';
		c+='    <p class="bb_pd_desc">';
		c+='        <a href="#">'+obj.goodsName+'</a>';
		c+='    </p>';
		c+='    <p class="bb_pd_opt">';       
		c+='    	<a class="bb_pd_meg" title="查看评论" href="javascript:goDetailCmt(\''+obj.goodsId+'\');"><b></b>&nbsp;'+obj.countComment+'</a>';
		c+='    	<a class="bb_pd_like" title="喜欢" href="javascript:addLike(\''+obj.goodsId+'\');"><b></b>&nbsp;<span id="likeCount_'+obj.goodsId+'">'+obj.countLike+'</span></a>';    
		c+='    </p>';
		c+='    <a class="bb_pd_explain" href="javascript:goDetail(\''+obj.goodsId+'\');">';
		c+='        <h3>推荐理由</h3>';
		c+='        <p>'+obj.recommend+'</p>';                               
		c+='    </a>';
		c+='</div>';
		c+='</li>';
	}	
	$('#goodsContent').html(c);
}
//移至上一页
function movePre(){	
	--curPage;	
	_doPage();    
}
//移至下一页
function moveNext(){
	++curPage;	
	_doPage();
}
//点击go
function clickGo(id){	
	curPage=parseInt($('#'+id).val());
	_doPage();
}
//页面刷新方法
function _doPage(){		
	if(curPage>allPage){
		curPage=allPage;		
	}else if(curPage<1){
		curPage=1;	
	}
	doQuery();
}
//刷新界面元素
function refreshPageUI(){	
	allPage=Math.floor(allCount/pageSize)+(allCount%pageSize==0?0:1);
	$("#preBt").attr("class", curPage>1?"page_pre":"page_pre_unable");
	$("#nextBt").attr("class", curPage<allPage?"page_next":"page_next_unable");
	$("#preBt_top").attr("class", curPage>1?"page_pre":"page_pre_unable");
	$("#nextBt_top").attr("class", curPage<allPage?"page_next":"page_next_unable");
	$("#page").val(curPage);
	$("#page_top").val(curPage);
	$("#allPage_show").html("页 共"+allPage+"页");
	$("#allPage_show_top").html("页 共"+allPage+"页");
}
//添加喜欢
function addLike(goodsId){	
	$.post("${ctx}/favorite!addLike.action", "goodsId="+goodsId ,function callback(txt){   
			var json = $.parseJSON(txt);
			if (json.code==0) {	
				$('#likeCount_'+goodsId).html(parseInt($('#likeCount_'+goodsId).html())+1);
			}else if (json.code==2) {	
				alert('已在喜欢列表中！');
			}else if (json.code==3) {	
				alert('请先登录！');
			}else{
				alert('添加喜欢失败！');
			}
		}	
	);
}
//-->
</script>
